package GUImk2;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;

import edu.washington.tcss360.burningpenguins.data.Role;

public class Button2 extends JButton {
	
	/**
	 * Allows serialization.
	 */
	private static final long serialVersionUID = -5496321187562278810L;


	/**
	 * Constructs a button for the gui with set sizes and color.
	 * @param title
	 */
	protected Button2(String title) {
		super(title);
		this.setBackground(Color.GRAY.brighter());
		this.setMinimumSize(new Dimension(180, 30));
		this.setPreferredSize(new Dimension(180, 30));
		this.setMaximumSize(new Dimension(180, 30));
	}
	
	// Apologies if this next method explodes into a "god" method.  SMG
	/**
	 * Sets the actionPerformed by this button.
	 * 
	 * @param type MainPanel.LayoutLabels determines type of action.
	 * @param frame the frame that the action will be performed on/by.
	 */
	protected void setPattern(final String type, final FullFrame frame) {
		this.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				int role;
//				System.err.printf("Button clicked, type = %s, current role = %d, ", type, frame.getRole());
				if(type.equals(MainPanel.LAYOUT_LABELS[0])) role = 0;
				else if(type.equals(MainPanel.LAYOUT_LABELS[12])) role = Role.AUTHOR;
				else if(type.equals(MainPanel.LAYOUT_LABELS[13])) role = Role.REVIEWER;
				else if(type.equals(MainPanel.LAYOUT_LABELS[14])) role = Role.SUBPROGRAM_CHAIR;
				else if(type.equals(MainPanel.LAYOUT_LABELS[15])) role = Role.PROGRAM_CHAIR;
				else role = frame.getRole();
//				System.err.printf("new role: %d\n", role);
				frame.updatePanels(type, role);
			}
			
		});
		
		
		
	}

}
